package com.yanqu.road.server.cmd.activity.horserun;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.HorseRunProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.horserun.CrossHorseRunActivity;
import com.yanqu.road.server.manager.activity.horserun.CrossHorseRunMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = CrossProtocol.C_HORSE_RUN_GET_OTHER_HORSE_DATA,desc = "小马快跑获取其他小马数据")
public class CrossHorseRunGetOtherHorseCmd extends CrossUnionCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        HorseRunProto.HorseRunGetOtherHorseDataReq req = HorseRunProto.HorseRunGetOtherHorseDataReq.parseFrom(packet.getBytes());
        CrossHorseRunActivity activity = CrossHorseRunMgr.getActivity(req.getActivityId(), groupId);
        if (activity == null) {
            HorseRunProto.HorseRunGetOtherHorseDataResp.Builder builder = HorseRunProto.HorseRunGetOtherHorseDataResp.newBuilder();
            builder.setRet(GameErrorCode.E_HORSE_RUN_ACTIVITY_NO_EXIST);
            MessageHelper.sendPacket(serverId, packet.getPlayerId(),
                    YanQuMessageUtils.buildMessage(ClientProtocol.U_HORSE_RUN_GET_OTHER_HORSE_DATA,builder.build())
            );
            return;
        }

        HorseRunProto.HorseRunGetOtherHorseDataResp.Builder otherHorseData = activity.getOtherHorseData(req.getTargetUserId());
        MessageHelper.sendPacket(serverId, packet.getPlayerId(),
                YanQuMessageUtils.buildMessage(ClientProtocol.U_HORSE_RUN_GET_OTHER_HORSE_DATA,otherHorseData.build()));
        return;
    }

    @Override
    public void sendData() {

    }
}
